package com.yimingkeji.mysql.rest;

import com.yimingkeji.mysql.entity.User;
import com.yimingkeji.mysql.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Describe:
 * @Auther: zhenlong.yang
 * @Date: 2018/12/1 20:50
 */
@RestController
@RequestMapping("/user")
public class UserResource {

    @Autowired
    private UserRepository userRepository;

    @GetMapping("")
    public List<User> list(){
        return userRepository.findAll();
    }

    @PostMapping("")
    public User add(@RequestBody User user){
        return userRepository.save(user);
    }

    @GetMapping("/sql")
    public List<User> sql(String name, int age){
        return userRepository.queryBySQL(name, age);
    }
}
